<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>评分 - 组件演示</title>
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../components/rating/rating.css">
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>🚀 openHarmony_Cordova_NutpiDesign</h1>
            <p class="subtitle">组件演示 - 评分</p>
        </header>

        <nav class="demo-nav">
            <a href="../index.html" class="nav-back">← 返回首页</a>
        </nav>

        <main class="main-content">
            <section class="demo-section">
                <h2>⭐ 评分演示</h2>
                
                <div class="demo-container">
                    <div class="demo-item">
                        <h3>基础评分</h3>
                        <div id="basicRating"></div>
                    </div>

                    <div class="demo-item">
                        <h3>半星评分</h3>
                        <div id="halfRating"></div>
                    </div>

                    <div class="demo-item">
                        <h3>小尺寸</h3>
                        <div id="smallRating"></div>
                    </div>

                    <div class="demo-item">
                        <h3>大尺寸</h3>
                        <div id="largeRating"></div>
                    </div>

                    <div class="demo-item">
                        <h3>只读状态</h3>
                        <div id="readonlyRating"></div>
                    </div>

                    <div class="demo-item">
                        <h3>禁用状态</h3>
                        <div id="disabledRating"></div>
                    </div>

                    <div class="demo-item">
                        <h3>10星评分</h3>
                        <div id="tenStarRating"></div>
                    </div>

                    <div class="demo-item">
                        <h3>实时反馈</h3>
                        <div id="feedbackRating"></div>
                        <p id="feedbackText" style="margin-top: 8px; font-size: 12px; color: var(--text-secondary);"></p>
                    </div>
                </div>
            </section>

            <section class="demo-section">
                <h2>使用代码</h2>
                <pre><code>// 1. 引入文件
&lt;link rel="stylesheet" href="components/rating/rating.css"&gt;
&lt;script src="components/rating/rating.js"&lt;/script&gt;

// 2. 创建容器
&lt;div id="ratingContainer"&lt;/div&gt;

// 3. 初始化评分组件
const rating = new Rating({
    container: '#ratingContainer',
    value: 3,
    count: 5,
    allowHalf: false,
    onChange: (result) => {
        console.log('评分:', result.value);
    }
});

// 4. 获取评分
const value = rating.getValue();

// 5. 设置评分
rating.setValue(4);

// 6. 禁用
rating.setDisabled(true);</code></pre>
            </section>
        </main>

        <footer class="footer">
            <p>&copy; 2025 OpenHarmony 三方库适配中心 | MIT License</p>
        </footer>
    </div>

    <script src="../components/rating/rating.js"></script>
    <script>
        // 基础评分
        new Rating({
            container: '#basicRating',
            value: 3,
            count: 5
        });

        // 半星评分
        new Rating({
            container: '#halfRating',
            value: 3.5,
            count: 5,
            allowHalf: true
        });

        // 小尺寸
        new Rating({
            container: '#smallRating',
            value: 4,
            count: 5,
            size: 'small'
        });

        // 大尺寸
        new Rating({
            container: '#largeRating',
            value: 4,
            count: 5,
            size: 'large'
        });

        // 只读状态
        new Rating({
            container: '#readonlyRating',
            value: 4,
            count: 5,
            readonly: true
        });

        // 禁用状态
        new Rating({
            container: '#disabledRating',
            value: 3,
            count: 5,
            disabled: true
        });

        // 10星评分
        new Rating({
            container: '#tenStarRating',
            value: 7,
            count: 10
        });

        // 实时反馈
        const feedbackRating = new Rating({
            container: '#feedbackRating',
            value: 0,
            count: 5,
            allowHalf: true,
            onChange: (result) => {
                const feedbackText = document.getElementById('feedbackText');
                const messages = ['很差', '差', '一般', '好', '很好'];
                const index = Math.floor(result.value) - 1;
                feedbackText.textContent = `您的评分: ${result.value} 星 - ${messages[index] || ''}`;
            }
        });
    </script>

    <style>
        .demo-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        .demo-item {
            background: var(--bg-light);
            padding: 16px;
            border-radius: 8px;
            overflow: visible;
            position: relative;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100px;
        }

        .demo-item h3 {
            margin-top: 0;
            margin-bottom: 16px;
            font-size: 14px;
            color: var(--text-primary);
            width: 100%;
            text-align: center;
        }

        .demo-item > div {
            display: flex;
            justify-content: center;
        }

        @media (max-width: 768px) {
            .demo-container {
                grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            }
        }
    </style>
</body>
</html>
